package com.zw.visual.controller;/*
 *@program:java-cloud-prevalence
 *@author:zw
 *@Time: 2022/12/15
 *@description: 主页可视化数据
 */

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zw.commons.utlis.HttpUtils;
import com.zw.object.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.alibaba.druid.support.json.JSONUtils;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "疫情数据可视化")
@RestController
@RequestMapping("/admin/system/visual")
public class VisualController {

    //TODO ：  改用REDIS存储高频数据
    @ApiOperation("历史疫情数据详情")
    @GetMapping("/history")
    public Result history() {
        String res = HttpUtils.sendGet("https://c.m.163.com/ug/api/wuhan/app/data/list-total");
        JSONObject jsonObject = JSONUtil.parseObj(res);
        String data = jsonObject.getByPath("data.chinaDayList").toString();
        return Result.ok(data);
    }

    @ApiOperation("风险区域")
    @GetMapping("/riskArea")
    public Result riskArea() {
        String res = HttpUtils.sendGet("https://m.sm.cn/api/rest?format=json&method=Huoshenshan.riskArea");
        JSONObject jsonObject = JSONUtil.parseObj(res);
        Object data = jsonObject.getByPath("data.map");
        return Result.ok(data);
    }

    @GetMapping("/infiniteNews")
    public Result infiniteNews(String id) {
        String url = StrUtil.isNotBlank(id) ? "https://m.sm.cn/api/rest?format=json&method=Huoshenshan.feed&type=latest&id=" + id : "https://m.sm.cn/api/rest?format=json&method=Huoshenshan.feed&type=latest";
        String res = HttpUtils.sendGet(url);
        JSONObject jsonObject = JSONUtil.parseObj(res);
        Object data = jsonObject.get("data");
        return Result.ok(data);
    }


    @GetMapping("/vaccineTopData")
    public Result vaccineTopData() {
        String res = HttpUtils.sendGet("https://api.inews.qq.com/newsqa/v1/automation/modules/list?modules=VaccineTopData");
        JSONObject jsonObject = JSONUtil.parseObj(res);
        Object object = jsonObject.getByPath("data.VaccineTopData");
        return Result.ok(object);
    }

    @GetMapping("/chinaVaccineTrendData")
    public Result chinaVaccineTrendData(){
        String res = HttpUtils.sendGet("https://api.inews.qq.com/newsqa/v1/automation/modules/list?modules=ChinaVaccineTrendData");
        JSONObject jsonObject = JSONUtil.parseObj(res);
        Object object = jsonObject.getByPath("data.ChinaVaccineTrendData");
        return Result.ok(object);
    }

    @GetMapping("/rumor")
    public Result rumor(String offset){
        String url = StrUtil.isNotBlank(offset) ? "https://c.m.163.com/ug/api/wuhan/app/article/list?limit=6&offset=" + offset : "https://c.m.163.com/ug/api/wuhan/app/article/list?limit=6";
        String res = HttpUtils.sendGet(url);
        JSONObject jsonObject = JSONUtil.parseObj(res);
        Object object = jsonObject.getByPath("data.items");
        return Result.ok(object.toString());
    }

    @GetMapping("/chinaData")
    public Result chinaData(){
        String res = HttpUtils.sendGet("https://c.m.163.com/ug/api/wuhan/app/data/list-total");
        Object object = JSONUtils.parse(res);
        return Result.ok(object);
    }

    @GetMapping("/news")
    public Result news(){
        String res = HttpUtils.sendGet("https://opendata.baidu.com/data/inner?tn=reserved_all_res_tn&dspName=iphone&from_sf=1&dsp=iphone&resource_id=28565&alr=1&query=%E5%9B%BD%E5%86%85%E6%96%B0%E5%9E%8B%E8%82%BA%E7%82%8E%E6%9C%80%E6%96%B0%E5%8A%A8%E6%80%81");
        JSONObject jsonObject = JSONUtil.parseObj(res);
        Object result = jsonObject.getByPath("Result[0].items_v2[0].aladdin_res.DisplayData.result.items");
        return Result.ok(result);
    }
}
